<!DOCTYPE html>
<html>
<head>
    <meta charset="UTF-8" />
    <title>主页 | 米尔豪斯酒店网上订餐</title>
    <link rel="stylesheet" type="text/css" href="../css/cart.css">

    <script type="text/javascript">
        function delete_1(productid) {
            window.location.href = "delete_1.php?productid="+productid;
        }
    </script>
</head>
<body>
<div class="all">
    <div class="all1">
        <div class="home">
            <div class="header">
                <div class="header1">
                    <div class="name">
                        <a href="index.php"><h1>米尔豪斯</h1></a>
                    </div>
                    <div class="guide">
                        <ul>
                            <li><a href="cart.php">购物车</a></li>
                            <li><a href="../register.html">注&nbsp;册</a></li>
                            <li><a href="../login.html">登&nbsp;陆</a></li>
                            <li><a href="zhongcan_order.php">点&nbsp;餐</a></li>
                            <li><a href="consult.php">留&nbsp;言</a></li>
                            <li><a href="index.php">主&nbsp;页</a></li>
                        </ul>
                    </div>
                </div>
            </div>

            <div class="header2">
                <div class="header3">
                    <h1>My Cart</h1>
                 </div>
            </div>

            <div class="bottom2">
                <img src="../img/border.png" alt="底线">
            </div>
        </div>

        <div class="middle">
            <div class="middle1">
                <ul>
                    <li><a href="index.php">主页</a></li>
                    <li class="middle3">/</li>
                    <li class="middle2">购物车</li>
                </ul>
            </div>
            <div class="bottom1">
                <img src="../img/border.png" alt="底线">
            </div>
        </div>
    </div>

    <div class="all2">
        <h1>Cart</h1>
        <div class="gwc">
            
            <form action="delete_1.php" method="get" >
                <table>
                <thead>
                    <tr>
                        <th><h3>菜品</h3></th>
                        <th><h3>数量</h3></th>
                        <th><h3>单价</h3></th>
                        <th><h3>总价</h3></th>
                        <th><h3>删除</h3></th>
                    </tr>
                </thead>
    <?php 
        error_reporting(0);
        session_start();
        header("Content-type:text/html;charset=utf-8");
        if(!isset($_SESSION['user_name']))
        {
            echo "<script>alert('登陆后查看购物车');location='index.php'</script>";
            die;
        }
        $user_name = $_SESSION['user_name'];
        $zongjia = 0;
        include "../../lib/DB.php";
        $db = new DB();
        $g = $db->table($user_name)->select();
        if(empty($g))
        {
            echo "<script>alert('暂无购物商品,请您先加入购物车');location='index.php'</script>";
            die;
        }
        foreach ($g as $row){

            $goods = $db->table('goods')->where(['gid' => $row['productid']])->find();
            $url = $_SERVER['SERVER_NAME']."/houtai/php/goods/";
    ?>

                <tr class="show">    
                    <td><img src="//<?php echo $url.$goods['goods_url'] ?>" width="150" height="100" class="food">
                        <br>
                        <span><?php echo $row['title'] ?></span></td>
                    <td><?php echo $row['num'] ?></td>
                    <td><?php echo $row['price'] ?>￥</td>
                    <td><?php echo $row['price']*$row['num']?></td>
                    <td><a href="javascript:delete_1(<?php echo $row['productid']?>)"><img src="../img/delete.png" class="delete"></a></td>
                </tr>           
    <?php     
        $zongjia += $row['price']*$row['num'];
        }
     ?>
                </table>
            </form>
            
        </div>
        <div class="gwc2">
            <p>共计：  <?php echo $zongjia ?>￥</p>
            <ul>
                <li class="jiesuan"><a href="jiesuan.php" >结算</a></li>
                <li class="qingkong"><a href="qingkong.php" >清空购物车</a></li>
                
            </ul>
        </div>
    </div>

    <div class="footer">
        <h1>欢迎来到米尔豪斯酒店订餐</h1>
    </div>

</div>
</body>
</html>